package www.wen.com.common.lib.view.popuview

import android.content.Context
import android.view.View
import android.widget.TextView
import www.wen.com.common.R
import www.wen.com.common.lib.extension.setOnClickListenerAgency
import www.wen.com.common.lib.helper.ResultUiCallBack

abstract class BaseClosePopupView<T>(
        context: Context,
        optionItems: List<T>,
        var title: CharSequence,
        val resultCallBack: ResultUiCallBack<T>? = null,
        resultSelectedListenerCallBack: ResultUiCallBack<T>? = null,
) : BaseSingleBottomSelectPopupView<T>(context, optionItems, resultSelectedListenerCallBack), View.OnClickListener {

    lateinit var mTvOk: View

    lateinit var mClose: View

    lateinit var mTvTitle: TextView

    override fun onCreate() {
        super.onCreate()
        mClose = findViewById(R.id.imgClose)
        mTvOk = findViewById(R.id.tvOK)
        mTvTitle = findViewById(R.id.tvTitle)
        mTvTitle.text = title
        setOnClickListenerAgency(this, mClose, mTvOk)
    }

    override fun onClick(v: View) {
        when (v.id) {

            R.id.imgClose -> dismiss()

            R.id.tvOK -> {
                resultCallBack?.invoke(v, selectItem!!, this@BaseClosePopupView)
            }
        }
    }

}